
package sistema;

import java.awt.Component;
import java.util.Calendar;
import javax.swing.JFormattedTextField;
import javax.swing.JPanel;
import javax.swing.JTextField;
import calculador.CalculaEmprestimo;
import empregadoDAO.EmpregadoDAOapp;
import empregadoDAO.exception.EmpregadoDAOException;
import java.text.NumberFormat;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import validacao.Exception.TamanhoNomeException;
import validacao.Exception.campoPreenchidoException;
import validacao.Exception.contratacaoException;
import validacao.Exception.cpfInvalidoException;
import validacao.Exception.idadeInvalidaException;
import validacao.Exception.salarioException;
import validacao.Exception.valorEmprestimoException;


/**
 *
 * @author user
 */
public class JanelaPrincipal extends javax.swing.JFrame {

       public JanelaPrincipal() {
        
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        JanelaAdicionar = new javax.swing.JFrame();
        jLabel1 = new javax.swing.JLabel();
        botaoAdicionar_Incluir = new javax.swing.JButton();
        botaoAdicionar_Cancelar = new javax.swing.JButton();
        painelAdicionarEmpregado = new javax.swing.JPanel();
        labelNome = new javax.swing.JLabel();
        labelCPF = new javax.swing.JLabel();
        labelSexo = new javax.swing.JLabel();
        labelNascimento = new javax.swing.JLabel();
        labelAdmissao = new javax.swing.JLabel();
        labelSalario = new javax.swing.JLabel();
        campoAdicionar_Nome = new javax.swing.JTextField();
        radioMasc = new javax.swing.JRadioButton();
        radioFem = new javax.swing.JRadioButton();
        campoAdicionar_DataNascimento = new javax.swing.JFormattedTextField();
        campoAdicionar_DataAdmissao = new javax.swing.JFormattedTextField();
        campoAdicionar_CPF = new javax.swing.JFormattedTextField();
        campoAdicionar_Salario = new javax.swing.JFormattedTextField();
        JanelaEmprestimo = new javax.swing.JFrame();
        painelSolicitarEmprestimo = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        campoEmprestimo_CPF = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        campoEmprestimo_Valor = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        comboEmprestimo_Prestacoes = new javax.swing.JComboBox();
        botaoEmprestimo_Solicitar = new javax.swing.JButton();
        botaoEmprestimo_Cancelar = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        buttonGroupSexo = new javax.swing.ButtonGroup();
        JanelaFuncionario = new javax.swing.JFrame();
        painelFuncionario = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        campoFuncionario_Nome = new javax.swing.JTextField();
        campoFuncionario_CPF = new javax.swing.JFormattedTextField();
        campoFuncionario_Salario = new javax.swing.JFormattedTextField();
        campoFuncionario_Sexo = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        campoFuncionario_DataNascimento = new javax.swing.JFormattedTextField();
        jLabel12 = new javax.swing.JLabel();
        campoFuncionario_DataAdmissao = new javax.swing.JFormattedTextField();
        jPanel2 = new javax.swing.JPanel();
        jLabel14 = new javax.swing.JLabel();
        campoFuncionario_DataDesligamento = new javax.swing.JFormattedTextField();
        jLabel7 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        botaoFuncionario_Modificar = new javax.swing.JButton();
        botaoFuncionario_Excluir = new javax.swing.JButton();
        botaoFuncionario_Credito = new javax.swing.JButton();
        botaoFuncionario_Sair = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        campoPrincipal_CPF = new javax.swing.JFormattedTextField();
        botaoPrincipal_Adicionar = new javax.swing.JButton();
        botaoPrincipal_Abrir = new javax.swing.JButton();

        JanelaAdicionar.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        JanelaAdicionar.setTitle("Incluir Novo Funcionário");
        JanelaAdicionar.setAlwaysOnTop(true);
        JanelaAdicionar.setBounds(new java.awt.Rectangle(250, 250, 0, 0));
        JanelaAdicionar.setMinimumSize(new java.awt.Dimension(266, 290));
        JanelaAdicionar.setResizable(false);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 20)); // NOI18N
        jLabel1.setText("Incluir Novo Funcionário");

        botaoAdicionar_Incluir.setText("Incluir");
        botaoAdicionar_Incluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoAdicionar_IncluirActionPerformed(evt);
            }
        });

        botaoAdicionar_Cancelar.setText("Cancelar");
        botaoAdicionar_Cancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoAdicionar_CancelarActionPerformed(evt);
            }
        });

        painelAdicionarEmpregado.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        labelNome.setText("Nome:");

        labelCPF.setText("CPF (números):");

        labelSexo.setText("Sexo:");

        labelNascimento.setText("Data de Nascimento:");

        labelAdmissao.setText("Data de Admissão:");

        labelSalario.setText("Salário Atual:");

        buttonGroupSexo.add(radioMasc);
        radioMasc.setSelected(true);
        radioMasc.setText("M");

        buttonGroupSexo.add(radioFem);
        radioFem.setText("F");

        try {
            campoAdicionar_DataNascimento.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        campoAdicionar_DataNascimento.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        try {
            campoAdicionar_DataAdmissao.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        campoAdicionar_DataAdmissao.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        campoAdicionar_CPF.setEditable(false);
        try {
            campoAdicionar_CPF.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("###.###.###-##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        campoAdicionar_CPF.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        campoAdicionar_Salario.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0.00"))));
        campoAdicionar_Salario.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        javax.swing.GroupLayout painelAdicionarEmpregadoLayout = new javax.swing.GroupLayout(painelAdicionarEmpregado);
        painelAdicionarEmpregado.setLayout(painelAdicionarEmpregadoLayout);
        painelAdicionarEmpregadoLayout.setHorizontalGroup(
            painelAdicionarEmpregadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelAdicionarEmpregadoLayout.createSequentialGroup()
                .addGroup(painelAdicionarEmpregadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(painelAdicionarEmpregadoLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(painelAdicionarEmpregadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(labelSalario)
                            .addComponent(labelAdmissao)
                            .addComponent(labelNascimento)
                            .addComponent(labelNome)
                            .addComponent(labelCPF)))
                    .addGroup(painelAdicionarEmpregadoLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(labelSexo)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(painelAdicionarEmpregadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(campoAdicionar_Nome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(campoAdicionar_CPF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(campoAdicionar_DataNascimento, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(campoAdicionar_DataAdmissao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(painelAdicionarEmpregadoLayout.createSequentialGroup()
                        .addComponent(radioMasc)
                        .addGap(26, 26, 26)
                        .addComponent(radioFem))
                    .addComponent(campoAdicionar_Salario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        painelAdicionarEmpregadoLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {campoAdicionar_CPF, campoAdicionar_DataAdmissao, campoAdicionar_DataNascimento, campoAdicionar_Nome, campoAdicionar_Salario});

        painelAdicionarEmpregadoLayout.setVerticalGroup(
            painelAdicionarEmpregadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelAdicionarEmpregadoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(painelAdicionarEmpregadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelNome)
                    .addComponent(campoAdicionar_Nome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(painelAdicionarEmpregadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelCPF)
                    .addComponent(campoAdicionar_CPF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(8, 8, 8)
                .addGroup(painelAdicionarEmpregadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelSexo)
                    .addComponent(radioMasc)
                    .addComponent(radioFem))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(painelAdicionarEmpregadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelNascimento)
                    .addComponent(campoAdicionar_DataNascimento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(painelAdicionarEmpregadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(labelAdmissao)
                    .addComponent(campoAdicionar_DataAdmissao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(painelAdicionarEmpregadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelSalario)
                    .addComponent(campoAdicionar_Salario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(14, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout JanelaAdicionarLayout = new javax.swing.GroupLayout(JanelaAdicionar.getContentPane());
        JanelaAdicionar.getContentPane().setLayout(JanelaAdicionarLayout);
        JanelaAdicionarLayout.setHorizontalGroup(
            JanelaAdicionarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(JanelaAdicionarLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(JanelaAdicionarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(JanelaAdicionarLayout.createSequentialGroup()
                        .addComponent(botaoAdicionar_Incluir, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(28, 28, 28)
                        .addComponent(botaoAdicionar_Cancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(painelAdicionarEmpregado, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        JanelaAdicionarLayout.setVerticalGroup(
            JanelaAdicionarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(JanelaAdicionarLayout.createSequentialGroup()
                .addGap(6, 6, 6)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(painelAdicionarEmpregado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(JanelaAdicionarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botaoAdicionar_Incluir)
                    .addComponent(botaoAdicionar_Cancelar))
                .addContainerGap(34, Short.MAX_VALUE))
        );

        JanelaEmprestimo.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        JanelaEmprestimo.setTitle("Solicitar Empréstimo Consignado");
        JanelaEmprestimo.setAlwaysOnTop(true);
        JanelaEmprestimo.setBounds(new java.awt.Rectangle(200, 200, 0, 0));
        JanelaEmprestimo.setMinimumSize(new java.awt.Dimension(370, 200));
        JanelaEmprestimo.setResizable(false);

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel3.setText("CPF do usuário:");

        campoEmprestimo_CPF.setEditable(false);
        campoEmprestimo_CPF.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel4.setText("Valor do Empréstimo:");

        jLabel5.setText("Prestações:");

        comboEmprestimo_Prestacoes.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18" }));

        botaoEmprestimo_Solicitar.setText("Solicitar");
        botaoEmprestimo_Solicitar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoEmprestimo_SolicitarActionPerformed(evt);
            }
        });

        botaoEmprestimo_Cancelar.setText("Cancelar");
        botaoEmprestimo_Cancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoEmprestimo_CancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout painelSolicitarEmprestimoLayout = new javax.swing.GroupLayout(painelSolicitarEmprestimo);
        painelSolicitarEmprestimo.setLayout(painelSolicitarEmprestimoLayout);
        painelSolicitarEmprestimoLayout.setHorizontalGroup(
            painelSolicitarEmprestimoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelSolicitarEmprestimoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(painelSolicitarEmprestimoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(painelSolicitarEmprestimoLayout.createSequentialGroup()
                        .addGroup(painelSolicitarEmprestimoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(painelSolicitarEmprestimoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(painelSolicitarEmprestimoLayout.createSequentialGroup()
                                .addComponent(campoEmprestimo_Valor, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(comboEmprestimo_Prestacoes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(campoEmprestimo_CPF))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(painelSolicitarEmprestimoLayout.createSequentialGroup()
                        .addComponent(botaoEmprestimo_Solicitar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(botaoEmprestimo_Cancelar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        painelSolicitarEmprestimoLayout.setVerticalGroup(
            painelSolicitarEmprestimoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelSolicitarEmprestimoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(painelSolicitarEmprestimoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(campoEmprestimo_CPF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(painelSolicitarEmprestimoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(campoEmprestimo_Valor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(comboEmprestimo_Prestacoes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(painelSolicitarEmprestimoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(painelSolicitarEmprestimoLayout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(botaoEmprestimo_Solicitar))
                    .addGroup(painelSolicitarEmprestimoLayout.createSequentialGroup()
                        .addComponent(botaoEmprestimo_Cancelar)
                        .addGap(0, 0, Short.MAX_VALUE))))
        );

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 20)); // NOI18N
        jLabel2.setText("Solicitar Empréstimo Consignado");

        javax.swing.GroupLayout JanelaEmprestimoLayout = new javax.swing.GroupLayout(JanelaEmprestimo.getContentPane());
        JanelaEmprestimo.getContentPane().setLayout(JanelaEmprestimoLayout);
        JanelaEmprestimoLayout.setHorizontalGroup(
            JanelaEmprestimoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(JanelaEmprestimoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(JanelaEmprestimoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(painelSolicitarEmprestimo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        JanelaEmprestimoLayout.setVerticalGroup(
            JanelaEmprestimoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(JanelaEmprestimoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2)
                .addGap(18, 18, 18)
                .addComponent(painelSolicitarEmprestimo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        JanelaFuncionario.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        JanelaFuncionario.setTitle("Funcionário");
        JanelaFuncionario.setBounds(new java.awt.Rectangle(250, 250, 0, 0));
        JanelaFuncionario.setMinimumSize(new java.awt.Dimension(532, 295));
        JanelaFuncionario.setResizable(false);

        jLabel8.setText("Nome:");

        jLabel9.setText("CPF:");

        jLabel10.setText("Sexo:");

        jLabel13.setText("Salário:");

        campoFuncionario_CPF.setEditable(false);
        try {
            campoFuncionario_CPF.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("###.###.###-##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        campoFuncionario_CPF.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        campoFuncionario_Salario.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0.00"))));
        campoFuncionario_Salario.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        campoFuncionario_Sexo.setEditable(false);

        jLabel11.setText("Data de Nascimento:");

        try {
            campoFuncionario_DataNascimento.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        campoFuncionario_DataNascimento.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        jLabel12.setText("Data de Admissão:");

        try {
            campoFuncionario_DataAdmissao.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        campoFuncionario_DataAdmissao.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        jLabel14.setText("Data de Desligamento:");

        try {
            campoFuncionario_DataDesligamento.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        campoFuncionario_DataDesligamento.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        campoFuncionario_DataDesligamento.setName("campoFuncionarioDesligamento"); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jLabel14)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(campoFuncionario_DataDesligamento, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel14)
                    .addComponent(campoFuncionario_DataDesligamento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(0, 11, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout painelFuncionarioLayout = new javax.swing.GroupLayout(painelFuncionario);
        painelFuncionario.setLayout(painelFuncionarioLayout);
        painelFuncionarioLayout.setHorizontalGroup(
            painelFuncionarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelFuncionarioLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(painelFuncionarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel8)
                    .addComponent(jLabel9)
                    .addComponent(jLabel13))
                .addGap(18, 18, 18)
                .addGroup(painelFuncionarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(campoFuncionario_Nome, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, painelFuncionarioLayout.createSequentialGroup()
                        .addGroup(painelFuncionarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(campoFuncionario_Salario, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(campoFuncionario_CPF))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel10)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(campoFuncionario_Sexo, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(painelFuncionarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(painelFuncionarioLayout.createSequentialGroup()
                        .addGroup(painelFuncionarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel11)
                            .addComponent(jLabel12))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(painelFuncionarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(campoFuncionario_DataAdmissao, javax.swing.GroupLayout.DEFAULT_SIZE, 75, Short.MAX_VALUE)
                            .addComponent(campoFuncionario_DataNascimento)))
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        painelFuncionarioLayout.setVerticalGroup(
            painelFuncionarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelFuncionarioLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(painelFuncionarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(painelFuncionarioLayout.createSequentialGroup()
                        .addGap(32, 32, 32)
                        .addComponent(campoFuncionario_CPF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(painelFuncionarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel13)
                            .addComponent(campoFuncionario_Salario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(31, Short.MAX_VALUE))
                    .addGroup(painelFuncionarioLayout.createSequentialGroup()
                        .addGroup(painelFuncionarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8)
                            .addComponent(campoFuncionario_Nome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel11)
                            .addComponent(campoFuncionario_DataNascimento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(painelFuncionarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel9)
                            .addGroup(painelFuncionarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(campoFuncionario_Sexo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel12)
                                .addComponent(campoFuncionario_DataAdmissao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))))
        );

        jLabel7.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel7.setText("FUNCIONÁRIO");

        botaoFuncionario_Modificar.setText("Modificar");
        botaoFuncionario_Modificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoFuncionario_ModificarActionPerformed(evt);
            }
        });

        botaoFuncionario_Excluir.setText("Excluir");
        botaoFuncionario_Excluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoFuncionario_ExcluirActionPerformed(evt);
            }
        });

        botaoFuncionario_Credito.setText("Solicitar Crédito");
        botaoFuncionario_Credito.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoFuncionario_CreditoActionPerformed(evt);
            }
        });

        botaoFuncionario_Sair.setText("Sair");
        botaoFuncionario_Sair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoFuncionario_SairActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout JanelaFuncionarioLayout = new javax.swing.GroupLayout(JanelaFuncionario.getContentPane());
        JanelaFuncionario.getContentPane().setLayout(JanelaFuncionarioLayout);
        JanelaFuncionarioLayout.setHorizontalGroup(
            JanelaFuncionarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSeparator1)
            .addGroup(JanelaFuncionarioLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(JanelaFuncionarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(JanelaFuncionarioLayout.createSequentialGroup()
                        .addComponent(painelFuncionario, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(JanelaFuncionarioLayout.createSequentialGroup()
                        .addGap(56, 56, 56)
                        .addComponent(botaoFuncionario_Modificar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(botaoFuncionario_Credito, javax.swing.GroupLayout.PREFERRED_SIZE, 238, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(botaoFuncionario_Excluir)
                        .addGap(0, 0, Short.MAX_VALUE))))
            .addGroup(JanelaFuncionarioLayout.createSequentialGroup()
                .addGroup(JanelaFuncionarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(JanelaFuncionarioLayout.createSequentialGroup()
                        .addGap(472, 472, 472)
                        .addComponent(botaoFuncionario_Sair))
                    .addGroup(JanelaFuncionarioLayout.createSequentialGroup()
                        .addGap(205, 205, 205)
                        .addComponent(jLabel7)))
                .addGap(0, 0, Short.MAX_VALUE))
        );
        JanelaFuncionarioLayout.setVerticalGroup(
            JanelaFuncionarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(JanelaFuncionarioLayout.createSequentialGroup()
                .addGap(6, 6, 6)
                .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(painelFuncionario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(JanelaFuncionarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(botaoFuncionario_Modificar)
                    .addGroup(JanelaFuncionarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(botaoFuncionario_Credito, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(botaoFuncionario_Excluir)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(botaoFuncionario_Sair)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        JanelaFuncionarioLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {botaoFuncionario_Credito, botaoFuncionario_Excluir, botaoFuncionario_Modificar});

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Gerenciador de Empregados");
        setBounds(new java.awt.Rectangle(200, 200, 0, 0));
        setMinimumSize(new java.awt.Dimension(203, 116));
        setResizable(false);

        jLabel6.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel6.setText("CPF DO EMPREGADO:");

        try {
            campoPrincipal_CPF.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("###.###.###-##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        campoPrincipal_CPF.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        campoPrincipal_CPF.setText("");

        botaoPrincipal_Adicionar.setText("ADD");
        botaoPrincipal_Adicionar.setMaximumSize(new java.awt.Dimension(70, 20));
        botaoPrincipal_Adicionar.setMinimumSize(new java.awt.Dimension(70, 20));
        botaoPrincipal_Adicionar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoPrincipal_AdicionarActionPerformed(evt);
            }
        });

        botaoPrincipal_Abrir.setText("ABRIR");
        botaoPrincipal_Abrir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoPrincipal_AbrirActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(campoPrincipal_CPF)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(botaoPrincipal_Adicionar, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, Short.MAX_VALUE)
                        .addComponent(botaoPrincipal_Abrir)))
                .addContainerGap())
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {botaoPrincipal_Abrir, botaoPrincipal_Adicionar});

        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(campoPrincipal_CPF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botaoPrincipal_Adicionar, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(botaoPrincipal_Abrir, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel6)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(18, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    empregadoDAO.EmpregadoDAOapp mapaFuncionarios = new EmpregadoDAOapp();
    validacao validar = new validacao();
    
    


    private void limpaCampos(JPanel painel) {
        Component components[] = painel.getComponents();

        for (int i = 0; i < components.length; i++) {

            if (components[i] instanceof JFormattedTextField) {
                ((JFormattedTextField) components[i]).setText("");
            } else if (components[i] instanceof JTextField) {
                ((JTextField) components[i]).setText("");
            }
        }
    }
    
    
    //Métodos de pegar informações dos campos
    private Calendar getCalendarioDoCampo(JFormattedTextField campo) {
        String[] splitDataNascim = campo.getText().split("/");
        Calendar dataCalendar = Calendar.getInstance();
        dataCalendar.set(Integer.parseInt(splitDataNascim[2]), Integer.parseInt(splitDataNascim[1]), Integer.parseInt(splitDataNascim[0]));
        return dataCalendar;
    }
    
    private String getCPFString(JFormattedTextField campo) {
        return campo.getText().replaceAll("\\W", "");
    }
    
    private double getSalarioDouble(JFormattedTextField campo) {
        return Double.parseDouble(campo.getText().replaceAll(",", "."));
    }
    
    //função criada para botar um "0" antes dos meses menores que 10 
    private String corrijeStringDataMenor10(Calendar calendario, int monthOrDate) {
        if (calendario.get(monthOrDate) < 10) {
            return ("0"+calendario.get(monthOrDate));
        } else {
            return ""+calendario.get(monthOrDate);
        }
    }
    
    private String getDataString(Calendar calendario) {
        return (corrijeStringDataMenor10(calendario, Calendar.DATE) + corrijeStringDataMenor10(calendario, Calendar.MONTH) + calendario.get(Calendar.YEAR));
    }

    private void preencheJanelaFuncionario(Empregado empregado) {
       campoFuncionario_Nome.setText(empregado.getNome());
       campoFuncionario_CPF.setText(String.valueOf(empregado.getCPF()));
       campoFuncionario_Salario.setText(String.valueOf(empregado.getSalario()));
       campoFuncionario_Sexo.setText(empregado.getSexo());

       campoFuncionario_DataNascimento.setText(getDataString(empregado.getDataNascimento()));
       campoFuncionario_DataAdmissao.setText(getDataString(empregado.getDataAdmissao()));
              
       //alguns empregados sem data deslig
       if (getDataString(empregado.getDataDesligamento()).equals("11111111")) {
           campoFuncionario_DataDesligamento.setText(" ");
       } else {
           campoFuncionario_DataDesligamento.setText(getDataString(empregado.getDataDesligamento())); 
       }
    }
    
    private void botaoAdicionar_CancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoAdicionar_CancelarActionPerformed
        limpaCampos(painelAdicionarEmpregado);
        JanelaAdicionar.dispose();
    }//GEN-LAST:event_botaoAdicionar_CancelarActionPerformed

    private void botaoEmprestimo_CancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoEmprestimo_CancelarActionPerformed
        JanelaEmprestimo.dispose();
    }//GEN-LAST:event_botaoEmprestimo_CancelarActionPerformed
        
    private void botaoPrincipal_AdicionarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoPrincipal_AdicionarActionPerformed

        String cpfUsuario = getCPFString(campoPrincipal_CPF);
        try {
            if(!validar.cpfExiste(cpfUsuario,mapaFuncionarios.listaEmpregados()))
            {
                if(validar.validarCPF(cpfUsuario))
                {
                    JanelaAdicionar.setVisible(true);
                    campoAdicionar_CPF.setText(cpfUsuario);
                }
            }
            else
            {
                JOptionPane.showMessageDialog(botaoPrincipal_Abrir,"CPF já cadastrado");
            }
        } catch (EmpregadoDAOException | cpfInvalidoException ex) {
            JOptionPane.showMessageDialog(botaoPrincipal_Abrir, ex.getMessage(), "Opa! Houve um erro", JOptionPane.WARNING_MESSAGE);
            
        }
           
    }//GEN-LAST:event_botaoPrincipal_AdicionarActionPerformed

    private void botaoAdicionar_IncluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoAdicionar_IncluirActionPerformed

        try {
            validar.confirmaCamposPreenchidos(painelAdicionarEmpregado);

            String cpfUsuario = getCPFString(campoAdicionar_CPF);

            Calendar dataNascim = getCalendarioDoCampo(campoAdicionar_DataNascimento);

            Calendar dataAdmiss = getCalendarioDoCampo(campoAdicionar_DataAdmissao);


            String sexo;
            if (radioMasc.isSelected()) {
                sexo = "Masculino";
            } else {
                sexo = "Feminino";
            }

            double salarioEmpregado = getSalarioDouble(campoAdicionar_Salario);

            try {
                validar.validaContratacao(dataNascim, dataAdmiss);
                validar.validaSalario(salarioEmpregado);
                validar.checaTamanhoNome(campoAdicionar_Nome.getText());

                Empregado empregado = new Empregado(cpfUsuario, campoAdicionar_Nome.getText(), sexo, dataNascim, dataAdmiss, salarioEmpregado);
                try {
                    mapaFuncionarios.salvarEmpregado(empregado);
                } catch (EmpregadoDAOException ex) {
                    Logger.getLogger(JanelaPrincipal.class.getName()).log(Level.SEVERE, null, ex);
                }

                JanelaAdicionar.dispose();
                limpaCampos(painelAdicionarEmpregado);
                JanelaFuncionario.setVisible(true);
                preencheJanelaFuncionario(empregado);

            } catch (contratacaoException | salarioException | TamanhoNomeException ex) {
                JOptionPane.showMessageDialog(JanelaAdicionar, ex.getMessage(), "Opa! Houve um erro", JOptionPane.WARNING_MESSAGE);
            }

        } catch (campoPreenchidoException ex) {
            JOptionPane.showMessageDialog(painelAdicionarEmpregado, ex.getMessage(), "Opa! Houve um erro", JOptionPane.WARNING_MESSAGE);
        }
    }//GEN-LAST:event_botaoAdicionar_IncluirActionPerformed


    private void botaoFuncionario_SairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoFuncionario_SairActionPerformed
        JanelaFuncionario.dispose();
        limpaCampos(painelFuncionario);

    }//GEN-LAST:event_botaoFuncionario_SairActionPerformed

    private void botaoFuncionario_ModificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoFuncionario_ModificarActionPerformed
        try {
            validar.confirmaCamposPreenchidos(painelFuncionario);

            Empregado empregado = new Empregado();
            try {
                empregado = mapaFuncionarios.obterEmpregado(getCPFString(campoFuncionario_CPF));
            } catch (EmpregadoDAOException ex) {
                Logger.getLogger(JanelaPrincipal.class.getName()).log(Level.SEVERE, null, ex);
            }
            try {

                validar.checaTamanhoNome(campoFuncionario_Nome.getText());
                validar.validaSalario(getSalarioDouble(campoFuncionario_Salario));
                validar.validaContratacao(getCalendarioDoCampo(campoFuncionario_DataNascimento), getCalendarioDoCampo(campoFuncionario_DataAdmissao));


                empregado.setNome(campoFuncionario_Nome.getText());
                empregado.setSalario(getSalarioDouble(campoFuncionario_Salario));
                empregado.setDataNascimento(getCalendarioDoCampo(campoFuncionario_DataNascimento));
                empregado.setDataAdmissao(getCalendarioDoCampo(campoFuncionario_DataAdmissao));


                if (!(campoFuncionario_DataDesligamento.getText().startsWith(" "))) {
                    empregado.setDataDesligamento(getCalendarioDoCampo(campoFuncionario_DataDesligamento));
                }

                try {
                    mapaFuncionarios.salvarEmpregado(empregado);
                } catch (EmpregadoDAOException ex) {
                    Logger.getLogger(JanelaPrincipal.class.getName()).log(Level.SEVERE, null, ex);
                }

                JOptionPane.showMessageDialog(JanelaFuncionario, "Empregado Modificado");


            } catch (TamanhoNomeException | salarioException | contratacaoException ex) {
                JOptionPane.showMessageDialog(JanelaFuncionario, ex.getMessage(), "Opa! Houve um erro", JOptionPane.WARNING_MESSAGE);
            }


        } catch (campoPreenchidoException ex) {
            JOptionPane.showMessageDialog(JanelaFuncionario, ex.getMessage(), "Opa! Houve um erro", JOptionPane.WARNING_MESSAGE);
        }    
    }//GEN-LAST:event_botaoFuncionario_ModificarActionPerformed

    private void botaoFuncionario_CreditoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoFuncionario_CreditoActionPerformed
        try {
            validar.validaEmprestimo(mapaFuncionarios.obterEmpregado(getCPFString(campoPrincipal_CPF)));
            JanelaEmprestimo.setVisible(true);
            campoEmprestimo_CPF.setText(campoFuncionario_CPF.getText());
            
        } catch (idadeInvalidaException | EmpregadoDAOException ex) {
            JOptionPane.showMessageDialog(JanelaFuncionario, ex.getMessage(), "Opa! Houve um erro", JOptionPane.WARNING_MESSAGE);
        }
    }//GEN-LAST:event_botaoFuncionario_CreditoActionPerformed

    private void botaoPrincipal_AbrirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoPrincipal_AbrirActionPerformed
        try {
           if(validar.cpfExiste(getCPFString(campoPrincipal_CPF),mapaFuncionarios.listaEmpregados()))
           {
               Empregado empregado = new Empregado();
               try {
               empregado = mapaFuncionarios.obterEmpregado(getCPFString(campoPrincipal_CPF));
        
               preencheJanelaFuncionario(empregado);
               JanelaFuncionario.setVisible(true);
        
               } catch (EmpregadoDAOException ex) {
                    Logger.getLogger(JanelaPrincipal.class.getName()).log(Level.SEVERE, null, ex);
                }    
           }
           if(!validar.cpfExiste(getCPFString(campoPrincipal_CPF),mapaFuncionarios.listaEmpregados()))
           {
               JOptionPane.showMessageDialog(painelAdicionarEmpregado,"CPF não cadastrado");
           }
    
        } catch (EmpregadoDAOException ex) {
            JOptionPane.showMessageDialog(painelAdicionarEmpregado, ex.getMessage(), "Opa! Houve um erro", JOptionPane.WARNING_MESSAGE);
        }  
    }//GEN-LAST:event_botaoPrincipal_AbrirActionPerformed

    private void botaoFuncionario_ExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoFuncionario_ExcluirActionPerformed
        
        int confirmaExclusao = JOptionPane.showConfirmDialog(JanelaFuncionario, "Deseja excluir o funcionário?", "Confirmar exclusão", JOptionPane.YES_NO_OPTION);
        
        if (confirmaExclusao == 0) {
            try {
                mapaFuncionarios.deletarEmpregado(getCPFString(campoPrincipal_CPF));
            } catch (EmpregadoDAOException ex) {
                Logger.getLogger(JanelaPrincipal.class.getName()).log(Level.SEVERE, null, ex);
            }
            limpaCampos(painelFuncionario);
            JanelaFuncionario.dispose();
        }
        
    }//GEN-LAST:event_botaoFuncionario_ExcluirActionPerformed

    private void botaoEmprestimo_SolicitarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoEmprestimo_SolicitarActionPerformed

        Integer prestacao = Integer.parseInt(comboEmprestimo_Prestacoes.getSelectedItem().toString());
        Double valor = Double.parseDouble(campoEmprestimo_Valor.getText().replaceAll(",", "."));
           
        try {
               validar.validaValorEmprestimo(mapaFuncionarios.obterEmpregado(getCPFString(campoPrincipal_CPF)), valor);
               
               CalculaEmprestimo calculador = new CalculaEmprestimo();
               Double cf = calculador.calculaCF(valor, prestacao);
               Double valPrestacao = calculador.calculaValPrestacao(valor, cf);
               Double totalPagar = calculador.totalPagar(valPrestacao, prestacao);
               Double totalJuros = calculador.totalJuros(totalPagar, valor);
               NumberFormat formatadorDecimais = NumberFormat.getInstance();
               formatadorDecimais.setMaximumFractionDigits(2);
        
                JOptionPane.showMessageDialog(JanelaEmprestimo, prestacao + " parcela(s) de: " + formatadorDecimais.format(valPrestacao) + "\n"
                + "Total a pagar: " + formatadorDecimais.format(totalPagar) + "\nTotal de Juros: " + formatadorDecimais.format(totalJuros), "Valores", JOptionPane.INFORMATION_MESSAGE);
        
           } catch (EmpregadoDAOException | valorEmprestimoException ex) {
               JOptionPane.showMessageDialog(JanelaEmprestimo, ex.getMessage(), "Opa! Houve um erro", JOptionPane.WARNING_MESSAGE);
        }    
    }//GEN-LAST:event_botaoEmprestimo_SolicitarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());


        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(JanelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(JanelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(JanelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(JanelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new JanelaPrincipal().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JFrame JanelaAdicionar;
    private javax.swing.JFrame JanelaEmprestimo;
    private javax.swing.JFrame JanelaFuncionario;
    private javax.swing.JButton botaoAdicionar_Cancelar;
    private javax.swing.JButton botaoAdicionar_Incluir;
    private javax.swing.JButton botaoEmprestimo_Cancelar;
    private javax.swing.JButton botaoEmprestimo_Solicitar;
    private javax.swing.JButton botaoFuncionario_Credito;
    private javax.swing.JButton botaoFuncionario_Excluir;
    private javax.swing.JButton botaoFuncionario_Modificar;
    private javax.swing.JButton botaoFuncionario_Sair;
    private javax.swing.JButton botaoPrincipal_Abrir;
    private javax.swing.JButton botaoPrincipal_Adicionar;
    private javax.swing.ButtonGroup buttonGroupSexo;
    private javax.swing.JFormattedTextField campoAdicionar_CPF;
    private javax.swing.JFormattedTextField campoAdicionar_DataAdmissao;
    private javax.swing.JFormattedTextField campoAdicionar_DataNascimento;
    private javax.swing.JTextField campoAdicionar_Nome;
    private javax.swing.JFormattedTextField campoAdicionar_Salario;
    private javax.swing.JTextField campoEmprestimo_CPF;
    private javax.swing.JTextField campoEmprestimo_Valor;
    private javax.swing.JFormattedTextField campoFuncionario_CPF;
    private javax.swing.JFormattedTextField campoFuncionario_DataAdmissao;
    private javax.swing.JFormattedTextField campoFuncionario_DataDesligamento;
    private javax.swing.JFormattedTextField campoFuncionario_DataNascimento;
    private javax.swing.JTextField campoFuncionario_Nome;
    private javax.swing.JFormattedTextField campoFuncionario_Salario;
    private javax.swing.JTextField campoFuncionario_Sexo;
    private javax.swing.JFormattedTextField campoPrincipal_CPF;
    private javax.swing.JComboBox comboEmprestimo_Prestacoes;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JLabel labelAdmissao;
    private javax.swing.JLabel labelCPF;
    private javax.swing.JLabel labelNascimento;
    private javax.swing.JLabel labelNome;
    private javax.swing.JLabel labelSalario;
    private javax.swing.JLabel labelSexo;
    private javax.swing.JPanel painelAdicionarEmpregado;
    private javax.swing.JPanel painelFuncionario;
    private javax.swing.JPanel painelSolicitarEmprestimo;
    private javax.swing.JRadioButton radioFem;
    private javax.swing.JRadioButton radioMasc;
    // End of variables declaration//GEN-END:variables
}
